package com.ddc.study.entity;

import com.google.gson.annotations.SerializedName;

import java.util.List;
import java.util.Objects;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * Created on 2018/4/28.
 *
 * @author lshun
 * @version 1.0
 */
public class Article {

    @SerializedName("apkLink")
    private String mApkLink;

    @SerializedName("author")
    private String mAuthor;

    @SerializedName("chapterId")
    private int mChapterId;

    @SerializedName("chapterName")
    private String mChapterName;

    @SerializedName("collect")
    private boolean mCollect;

    @SerializedName("courseId")
    private int mCourseId;

    @SerializedName("desc")
    private String mDesc;

    @SerializedName("envelopePic")
    private String mEnvelopePic;

    @SerializedName("fresh")
    private boolean mFresh;

    @SerializedName("id")
    private int mId;

    @SerializedName("link")
    private String mLink;

    @SerializedName("niceDate")
    private String mNiceDate;

    @SerializedName("origin")
    private String mOrigin;

    @SerializedName("projectLink")
    private String mProjectLink;

    @SerializedName("publishTime")
    private long mPublishTime;

    @SerializedName("superChapterId")
    private int mSuperChapterId;

    @SerializedName("superChapterName")
    private String mSuperChapterName;

    @Nullable
    @SerializedName("tags")
    private List<Tag> mTags;

    @SerializedName("title")
    private String mTitle;

    @SerializedName("type")
    private int mType;

    @SerializedName("userId")
    private int mUserId;

    @SerializedName("visible")
    private int mVisible;

    @SerializedName("zan")
    private int mZan;

    public String getApkLink() {
        return mApkLink;
    }

    public void setApkLink(String apkLink) {
        mApkLink = apkLink;
    }

    public String getAuthor() {
        return mAuthor;
    }

    public void setAuthor(String author) {
        mAuthor = author;
    }

    public int getChapterId() {
        return mChapterId;
    }

    public void setChapterId(int chapterId) {
        mChapterId = chapterId;
    }

    public String getChapterName() {
        return mChapterName;
    }

    public void setChapterName(String chapterName) {
        mChapterName = chapterName;
    }

    public boolean isCollect() {
        return mCollect;
    }

    public void setCollect(boolean collect) {
        mCollect = collect;
    }

    public int getCourseId() {
        return mCourseId;
    }

    public void setCourseId(int courseId) {
        mCourseId = courseId;
    }

    public String getDesc() {
        return mDesc;
    }

    public void setDesc(String desc) {
        mDesc = desc;
    }

    public String getEnvelopePic() {
        return mEnvelopePic;
    }

    public void setEnvelopePic(String envelopePic) {
        mEnvelopePic = envelopePic;
    }

    public boolean isFresh() {
        return mFresh;
    }

    public void setFresh(boolean fresh) {
        mFresh = fresh;
    }

    public int getId() {
        return mId;
    }

    public void setId(int id) {
        mId = id;
    }

    public String getLink() {
        return mLink;
    }

    public void setLink(String link) {
        mLink = link;
    }

    public String getNiceDate() {
        return mNiceDate;
    }

    public void setNiceDate(String niceDate) {
        mNiceDate = niceDate;
    }

    public String getOrigin() {
        return mOrigin;
    }

    public void setOrigin(String origin) {
        mOrigin = origin;
    }

    public String getProjectLink() {
        return mProjectLink;
    }

    public void setProjectLink(String projectLink) {
        mProjectLink = projectLink;
    }

    public long getPublishTime() {
        return mPublishTime;
    }

    public void setPublishTime(long publishTime) {
        mPublishTime = publishTime;
    }

    public int getSuperChapterId() {
        return mSuperChapterId;
    }

    public void setSuperChapterId(int superChapterId) {
        mSuperChapterId = superChapterId;
    }

    public String getSuperChapterName() {
        return mSuperChapterName;
    }

    public void setSuperChapterName(String superChapterName) {
        mSuperChapterName = superChapterName;
    }

    public List<Tag> getTags() {
        return mTags;
    }

    public void setTags(List<Tag> tags) {
        mTags = tags;
    }

    public String getTitle() {
        return mTitle;
    }

    public void setTitle(String title) {
        mTitle = title;
    }

    public int getType() {
        return mType;
    }

    public void setType(int type) {
        mType = type;
    }

    public int getUserId() {
        return mUserId;
    }

    public void setUserId(int userId) {
        mUserId = userId;
    }

    public int getVisible() {
        return mVisible;
    }

    public void setVisible(int visible) {
        mVisible = visible;
    }

    public int getZan() {
        return mZan;
    }

    public void setZan(int zan) {
        mZan = zan;
    }

    @NonNull
    @Override
    public String toString() {
        return "Article{" +
                "mApkLink='" + mApkLink + '\'' +
                ", mAuthor='" + mAuthor + '\'' +
                ", mChapterId=" + mChapterId +
                ", mChapterName='" + mChapterName + '\'' +
                ", mCollect=" + mCollect +
                ", mCourseId=" + mCourseId +
                ", mDesc='" + mDesc + '\'' +
                ", mEnvelopePic='" + mEnvelopePic + '\'' +
                ", mFresh=" + mFresh +
                ", mId=" + mId +
                ", mLink='" + mLink + '\'' +
                ", mNiceDate='" + mNiceDate + '\'' +
                ", mOrigin='" + mOrigin + '\'' +
                ", mProjectLink='" + mProjectLink + '\'' +
                ", mPublishTime=" + mPublishTime +
                ", mSuperChapterId=" + mSuperChapterId +
                ", mSuperChapterName='" + mSuperChapterName + '\'' +
                ", mTags=" + mTags +
                ", mTitle='" + mTitle + '\'' +
                ", mType=" + mType +
                ", mUserId=" + mUserId +
                ", mVisible=" + mVisible +
                ", mZan=" + mZan +
                '}';
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (obj == this) return true;
        if (obj instanceof Article) {
            Article article = (Article) obj;

            if (!Objects.equals(article.mApkLink, mApkLink)) return false;
            if (!Objects.equals(article.mAuthor, mAuthor)) return false;
            if (article.mChapterId != mChapterId) return false;
            if (!Objects.equals(article.mChapterName, mChapterName)) return false;
            if (article.mCollect != mCollect) return false;
            if (article.mCourseId != mCourseId) return false;
            if (!Objects.equals(article.mDesc, mDesc)) return false;
            if (!Objects.equals(article.mEnvelopePic, mEnvelopePic)) return false;
            if (article.mFresh != mFresh) return false;
            if (article.mId != mId) return false;
            if (!Objects.equals(article.mLink, mLink)) return false;
            if (!Objects.equals(article.mNiceDate, mNiceDate)) return false;
            if (!Objects.equals(article.mOrigin, mOrigin)) return false;
            if (!Objects.equals(article.mProjectLink, mProjectLink)) return false;
            if (article.mPublishTime != mPublishTime) return false;
            if (article.mSuperChapterId != mSuperChapterId) return false;
            if (!Objects.equals(article.mSuperChapterName, mSuperChapterName)) return false;
            if (!Objects.deepEquals(article.mTags, mTags)) return false;
            if (article.mTags == null) {
                if (mTags != null) return false;
            } else {
                if (mTags == null) return false;
                if (!article.mTags.containsAll(mTags)) return false;
                if (mTags.containsAll(article.mTags)) return false;
            }
            if (!Objects.equals(article.mTitle, mTitle)) return false;
            if (article.mType != mType) return false;
            if (article.mUserId != mUserId) return false;
            if (article.mVisible != mVisible) return false;
            return article.mZan == mZan;
        }
        return false;
    }

    private static class Tag {
        @SerializedName("name")
        private String mName;
        @SerializedName("url")
        private String mUrl;

        public String getName() {
            return mName;
        }

        public void setName(String name) {
            mName = name;
        }

        public String getUrl() {
            return mUrl;
        }

        public void setUrl(String url) {
            mUrl = url;
        }

        @NonNull
        @Override
        public String toString() {
            return "Tag{" +
                    "mName='" + mName + '\'' +
                    ", mUrl='" + mUrl + '\'' +
                    '}';
        }

        @Override
        public boolean equals(@Nullable Object obj) {
            if (obj == this) return true;
            if (obj instanceof Tag) {
                Tag tag = (Tag) obj;
                if (!Objects.equals(tag.mName, mName)) return false;
                return Objects.equals(tag.mUrl, mUrl);
            }
            return false;
        }
    }
}
